import {ApiProperty} from "@nestjs/swagger";
import {IsDefined, Matches} from "class-validator";
import {IsFile} from "../tools/upload/file.constraint";
import {MultipartFile} from "@fastify/multipart";

export class AccessUploadDto {

  @ApiProperty({type: 'string', format: 'binary', description: '文件'})
  @IsDefined()
  @IsFile(
    {
      mimetypes: [
        'image/png',
        'image/gif',
        'image/jpeg',
        'image/webp',
        'image/svg+xml',
      ],
      fileSize: 1024 * 1024 * 10,
    },
    {
      message: '文件类型不正确',
    },
  )
  file: MultipartFile

  // 经度、纬度、房主姓名、房主出生日期、标签
  @ApiProperty({description: '经度'})
  @IsDefined()
  longitude: number

  @ApiProperty({description: '纬度'})
  @IsDefined()
  latitude: number

  @ApiProperty({description: '房主姓名'})
  @IsDefined()
  ownerName: string

  @ApiProperty({description: '房主出生日期'})
  @IsDefined()
  @Matches(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, {message: '日期格式必须为 YYYY-MM-DD hh:mm:ss'})
  ownerBirth: string
}
